//
//  ViewController.swift
//  Demo-9 识别捏合手势
//
//  Created by quanhao huang on 2019/9/29.
//  Copyright © 2019 demo. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var scalingView: UIView!
    //当前视图缩放程度
    var scale:Float = 1.0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //创建捏合手势
        let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinched(pinchGesture:)))
        
        self.scalingView.isUserInteractionEnabled = true
        self.scalingView.addGestureRecognizer(pinchGesture)
    }

    @objc func pinched(pinchGesture: UIPinchGestureRecognizer) {
        switch pinchGesture.state {
        case .changed:
            self.scale = Float(pinchGesture.scale)
//            pinchGesture.scale = 1.0
            
            self.scalingView.transform = CGAffineTransform(scaleX: CGFloat(self.scale), y: CGFloat(self.scale))
            break
        default:
            break
        }
    }

}

